<html>
<body>

alpha:<span id="alpha"></span><br/>
beta:<span id="beta"></span><br/>
gamma:<span id="gamma"></span><br/>
<script>
gyrox=0;

setTimeout(func1,7000)
function func1(){
	alert(gyrox)
}

function in_array(search,array){
    for(var i in array){
        if(array[i]==search){
            return true;
        }
    }
    return false;
}

if(window.DeviceOrientationEvent) {
	gav = new Array()
	gbv = new Array()
	ggv = new Array()
    window.addEventListener('deviceorientation', function(event) {
  	var a = document.getElementById('alpha'),
          b = document.getElementById('beta'),
          g = document.getElementById('gamma'),
          alpha = event.alpha,
          beta = event.beta,
          gamma = event.gamma;

  a.innerHTML = Math.round(alpha*100);
  b.innerHTML = Math.round(beta*100);
  g.innerHTML = Math.round(gamma*100);

window.ga = Math.round(alpha*100);
window.gb = Math.round(beta*100);
window.gg = Math.round(gamma*100);

if(!in_array(window.ga,gav)){
	gav.push(window.ga)
}
if(!in_array(window.gb,gbv)){
	gbv.push(window.gb)
}
if(gav.length >3 && gbv.length>3){
	window.gyrox=9
	console.log(gbv)
}



    }, false);
}else{
    document.querySelector('body').innerHTML = '你的瀏覽器不支援喔';
}
</script>
</body>
</html>